package jwm.event;

import java.util.ArrayList;
import java.util.List;

public class EventDispatcher implements Dispatcher {

   private List<EventListener> listeners;
   
   public EventDispatcher() {
      listeners = new ArrayList<EventListener>();
   }
   
   public void dispatchEvent(Event event) {
      synchronized (listeners) {
         for (int i = 0; i < listeners.size(); i++) {
            listeners.get(i).receiveEvent(event);
         }
      }
   }
   
   public void addEventListener(EventListener listener) {
      synchronized (listeners) {
         listeners.add(listener);
      }
   }
   
   public void removeEventListener(Object listener) {
      synchronized (listeners) {
         listeners.remove(listener);
      }
   }
   
}
